# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=cfitsio

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.360
pkgrel=1
pkgdesc="A library of C and Fortran subroutines for reading and writing data files in FITS (Flexible Image Transport System) data format (mingw-w64)"
arch=('any')
url="http://heasarc.gsfc.nasa.gov/fitsio/"
license=("custom")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
options=('strip' 'staticlibs')
source=("ftp://heasarc.gsfc.nasa.gov/software/fitsio/c/${_realname}${pkgver/./}.tar.gz"
    mingw-shared.patch)
md5sums=('833032c9ecbf1d460aca0360a26958db'
         '3f1e57458f0a0894fe66da3444bd35f1')

prepare() {
  cd ${_realname}
  patch -p1 -i ${srcdir}/mingw-shared.patch
  autoreconf -fi
}

build() {
  #export lt_cv_deplibs_check_method='pass_all'

  cd "${srcdir}/${_realname}"
  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST}
    make shared
}

check() {
  cd ${_realname}
  make testprog
  LD_LIBRARY_PATH=. ./testprog > testprog.lis
  [[ -z $(diff testprog.lis testprog.out) ]] || return 1
  [[ -z $(cmp testprog.fit testprog.std) ]] || return 1
}

package() {
  cd "${srcdir}/${_realname}"
  make DESTDIR="${pkgdir}" install
  mkdir -p "${pkgdir}${MINGW_PREFIX}"/bin
  mv "${pkgdir}${MINGW_PREFIX}"/lib/*.dll "${pkgdir}${MINGW_PREFIX}"/bin/
  install -D -m644 License.txt "${pkgdir}${MINGW_PREFIX}"/share/licenses/${_realname}/LICENSE
}
